package com.bt.lms.service.impl;

import com.bt.lms.bo.FinishedTeachingArrange;
import com.bt.lms.bo.NoStartTeachingArrange;
import com.bt.lms.bo.ProcessTeachingArrange;
import com.bt.lms.entity.TeachingArrangeInfo;
import com.bt.lms.dao.servise.TeachingArrangeDao;
import com.bt.lms.dao.servise.impl.TeachingArrangeDaoImpl;
import com.bt.lms.entity.page.Page;
import com.bt.lms.service.TeachingArrangeService;

import java.sql.*;


/**
 * 教学安排服务类
 *
 * @author 朱传博
 */

public class TeachingArrangeServiceImpl implements TeachingArrangeService {

    @Override
    public boolean add(TeachingArrangeInfo teachingArrangeInfo) throws ClassNotFoundException, SQLException {


        //维护不是输入的属性
        teachingArrangeInfo.getStatus();//未实施的教学安排状态

        //教学安排表

        //sql语句
        String sql = "insert into teaching_arrange(course_name,teaching_name,class_name,teaching_way,start_course_time,finish_course_time,course_aim)values(?,?,?,?,?,?,?)";

        //调方法
        TeachingArrangeDao teachingArrangeDao = new TeachingArrangeDaoImpl();
        teachingArrangeDao.insert(sql, teachingArrangeInfo);

        return true;
    }


    @Override
    public boolean addAffirmCourseStart(TeachingArrangeInfo teachingArrangeInfo) throws SQLException {

        //sql 语句

        String sql = "insert into teaching_arrange(course_name,teaching_name,class_name,teaching_way,start_course_time,finish_course_time,course_aim,teaching_arrange_status)values(?,?,?,?,?,?,?,?)";


        //调方法

        TeachingArrangeDao teachingArrangeDao = new TeachingArrangeDaoImpl();
        teachingArrangeDao.insert1(sql, teachingArrangeInfo);


        return false;
    }


    @Override
    public boolean edit(TeachingArrangeInfo teachingArrangeInfo, Long teachingArrangeID) throws SQLException, ClassNotFoundException {

        //维护不是输入的属性
        teachingArrangeInfo.getStatus();//未实施的教学安排状态

        //sql语句.
        String sql = "update teaching_arrange set course_name=?,teaching_name=?,class_name=?,teaching_way=?,start_course_time=?,finish_course_time=?,course_aim=? where id=?";

        //掉方法
        TeachingArrangeDao teachingArrangeDao = new TeachingArrangeDaoImpl();
        teachingArrangeDao.edit(sql, teachingArrangeInfo, teachingArrangeID);

        return true;
    }

    @Override
    public boolean delete(Long teachingArrangeID) throws SQLException, ClassNotFoundException {

        //sql语句
        String sql = "update teaching_arrange set deleted=? where id= ?";
        //掉方法
        TeachingArrangeDao teachingArrangeDao = new TeachingArrangeDaoImpl();
        teachingArrangeDao.delete(sql, teachingArrangeID);


        return true;
    }


    @Override
    public boolean affirmCourseStart(Long teachingArrangeID) throws SQLException, ClassNotFoundException {


        //sql语句
        String sql = "update teaching_arrange  set teaching_arrange_status= ? where id=?";
        //掉方法
        TeachingArrangeDao teachingArrangeDao = new TeachingArrangeDaoImpl();
        teachingArrangeDao.affirmCourseStart(sql, teachingArrangeID);


        return true;
    }


    @Override
    public TeachingArrangeInfo queryDetail(Long teachingArrangeID) throws SQLException, ClassNotFoundException {


        //要执行的sql语句
        String sql = "select*from teaching_arrange where id= ?";


        TeachingArrangeDao teachingArrangeDao = new TeachingArrangeDaoImpl();
        teachingArrangeDao.queryDetail(sql, teachingArrangeID);


        return null;
    }

    @Override
    public Page<TeachingArrangeInfo> pagingConditionQueryNoStartTA(Page<NoStartTeachingArrange> page) throws SQLException {


        //sql 语句
        String sql = "SELECT*FROM teaching_arrange limit ?,?";

        //调用
        TeachingArrangeDao teachingArrangeDao = new TeachingArrangeDaoImpl();
        Page<TeachingArrangeInfo> teachingArrangeInfoPage = teachingArrangeDao.pageQueryNoStart(sql, page);

        return teachingArrangeInfoPage;
    }

    @Override
    public Page<TeachingArrangeInfo> pagingConditionQueryProcess(Page<ProcessTeachingArrange> page) throws SQLException {

        //sql 语句
        String sql = "SELECT*FROM teaching_arrange limit ?,?";

        //调用
        TeachingArrangeDao teachingArrangeDao = new TeachingArrangeDaoImpl();
        Page<TeachingArrangeInfo> teachingArrangeInfoPage = teachingArrangeDao.pageQueryProcess(sql, page);

        return teachingArrangeInfoPage;
    }

    @Override
    public Page<TeachingArrangeInfo> pagingConditionQueryFinished(Page<FinishedTeachingArrange> page) throws SQLException {

        //sql 语句
        String sql = "SELECT*FROM teaching_arrange limit ?,?";

        //调用
        TeachingArrangeDao teachingArrangeDao = new TeachingArrangeDaoImpl();
        Page<TeachingArrangeInfo> teachingArrangeInfoPage = teachingArrangeDao.pageQueryFinish(sql, page);


        return teachingArrangeInfoPage;
    }
}
